import { FindOptions, MongoClient, ObjectId, UpdateFilter } from "mongodb";

const url = "mongodb://127.0.0.1:27017/";
const client = new MongoClient(url);

async function run() {
  try {
    await client.connect();
    const db = client.db("hello");
    const res = await db.command({ ping: 1 }); // 测试数据库是否成功
    console.log("connected", res);
    const userCollection = db.collection("user");
    const teamCollection = db.collection("team");
    const lakerTeam = await teamCollection.findOne({ name: "Nets" });
    const players = await userCollection.find({ team: lakerTeam._id }).toArray();
    const netPlayers = await userCollection.find({ _id: { $in: lakerTeam.players } }).toArray();
    console.log(netPlayers);
    console.log(players);
  } catch (error) {
    console.error("error", error);
  } finally {
    await client.close();
  }
}

run();
